module.exports = function ($scope, $state, $resource,$modal, $timeout, $stateParams, toaster) {

  /* 分页
      * ========================================= */
      $scope.maxSize = 5;            //最多显示多少个按钮
      $scope.bigCurrentPage = 1;      //当前页码
      $scope.itemsPerPage = 10;         //每页显示几条
      $scope.searchform = {};
      var tcode = $stateParams.gcode

      $scope.load = function () {
          var para = {
            gcode:$stateParams.gcode,
            tel:$scope.searchform.tel,
            people_idcard:$scope.searchform.people_idcard,
            name:$scope.searchform.name,
            pageNo: $scope.bigCurrentPage,
            pageSize: $scope.itemsPerPage,
          };
          para = angular.extend($scope.searchform, para);
          console.log($stateParams.gcode);
          $resource('/api/as/ggc/tourgroupafter/findtgpeopleList', {}, {}).save(para,function (res) {
    
            if (res.errcode !== 0) {
              alert("数据获取失败");
              return;
            }
      
            $scope.objs = res.data.results;
            $scope.bigTotalItems = res.data.totalRecord;
            $scope.bigCurrentPage = res.data.pageNo;
      
          });
      };
    $scope.load();
    
    $scope.add = function () {
      // alert("我要添加游团成员！");
      var modalInstance = $modal.open({
        template: require('../views/createpeo.html'),
        controller: 'createpeo',
        size: 'lg',
        resolve: {
          tcode:function(){
            return tcode;
          }
        }
    });
    modalInstance.result.then(function (showResult) {	
      $scope.load();
    });
    }

    $scope.update = function(pcode) {
      var modalInstance = $modal.open({
        template: require('../views/updatepeo.html'),
        controller: 'updatepeo',
        size: 'xs',
        resolve: {
          pcode:function(){
            return pcode;
          }
        }
      });
      modalInstance.result.then(function (showResult) {	
        $scope.load();
      });
    }


    $scope.del = function (code) {
      if(confirm("您确认要删除吗？")){
      $resource('/api/as/ggc/tourgroupafter/updatePeopleDel', {}, {}).save({'people_code':code},function (res) {
        if (res.errcode === 0) {
          toaster.success({ title: "提示", body: "删除成功！"});
          $scope.load();
        } else {
          toaster.error({ title: "提示", body: res.errmsg });
        }
      });
    }
  }
}